package chaoyue.study.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;

/**
 * 给RestTemplate配置的拦截器（注意不是MVC的拦截器）
 */
@Slf4j
public class MyRestTemplateInterceptor implements ClientHttpRequestInterceptor {
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        log.info("RestTemplate 拦截器 - pre！");
        ClientHttpResponse response = execution.execute(request,body);
        log.info("RestTemplate 拦截器 - post！");
        return response;
    }
}
